package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface OrderMapper {
    //新增订单
    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     *
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据主键id获得订单数据
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders selectById(Long id);


    /**
     * 取消订单
     * @param
     */
    @Update("update orders set status =#{status} where id =#{id}")
    void cancel(Integer status,Long id);


    /**
     * 根据订单id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id =#{id}")
    Orders getByOrdersId(Long id);

    //根据订单id查询订单
    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);

    /**
     * 统计待接单数量
     *
     * @param status
     */
    @Select("select count(*) from orders where status=#{status}")
    Integer counttoBeConfirmed(Integer status);

    /**
     * 统计待派送数量
     * @param status
     * @return
     */
    @Select("select count(*)from orders where status=#{status}")
    Integer confirmed(Integer status);

    /**
     * 统计派送成功数量
     * @param status
     * @return
     */
    @Select("select count(*)from orders where status=#{status}")
    Integer deliveryInProgress(Integer status);

   /* @Options(useGeneratedKeys = true, keyProperty = "id")
    @Select("select * from orders where status=#{status} and user_id=#{userId}")
    Orders getByS(Integer status, Long userId);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Select("select * from orders where status=#{status} and user_id=#{userId}")
    Orders getByStatus(Integer status, Long userId);*/



    /**
     * 用户端查询历史订单(即分页查询)+条件查询
     *
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageUser(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 商家订单搜索(条件查询)
     *
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageAdmin(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id};")
    Orders getByOrderId(Long id);
}
